<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * 餐桌分类
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$store_id=$this->store_id;
if(!$store_id){
	exi('请先选择门店！','error');
}
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['store_id']=$store_id;
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','title','money','pay');
	$list=pdo_getslice('jy_weishop_table_group',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'桌台类型列表'),
			array('op'=>'edit','title'=>'添加桌台类型'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'title','title'=>'类型名称','type'=>'string'),
			array('name'=>'money','title'=>'最低消费','type'=>'string'),
			array('name'=>'pay','title'=>'预定费用','type'=>'string'),
		)),
		'search_one'=>array('name'=>'title'),
	);
	$return['htmls']=$htmls;
	set_html('framess',$this->menustore());
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_weishop_table_group',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回餐桌类型列表'),
		),
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'类型名称','name'=>'title','help'=>''),
					array('type'=>'string','title'=>'此类餐桌最低消费','name'=>'money','help'=>''),
					array('type'=>'string','title'=>'预定定金','name'=>'pay','help'=>''),
					array('name'=>'fufee','title'=>'服务费','type'=>'unitstring','unit'=>'元/小时','help'=>'特定点餐环境才支持！'),
					array('name'=>'manfufee','title'=>'满多少元免服务费','type'=>'unitstring','unit'=>'元'),
				)
			),
		)
	);
	$return['htmls']=$htmls;
	set_html('framess',$this->menustore());
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'title'=>trim($postdata['title']),
		'fufee'=>trim($postdata['fufee']),
		'manfufee'=>trim($postdata['manfufee']),
		'money'=>intval($postdata['money']),
		'pay'=>intval($postdata['pay']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_weishop_table_group',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['store_id']=$store_id;
		pdo_insert('jy_weishop_table_group',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_weishop_table_group',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}